package com.flycms.module.soft.service;

import com.flycms.core.entity.PageVo;
import com.flycms.module.soft.dao.CaseDao;
import com.flycms.module.soft.model.Case;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author huangzt
 * @version 1.0
 * @date 2020/3/9 19:11
 */
@Service
public class SoftCaseService {

    @Autowired
    CaseDao caseVoCaseDao;


    public int insert(Case caseVo){
        return caseVoCaseDao.insert(caseVo);
    }

    public int update(Case caseVo){
        return caseVoCaseDao.update(caseVo);
    }

    public Case queryByPk(Integer id){
        return caseVoCaseDao.queryByPk(id);
    }

    public int delete(Integer id){
        return caseVoCaseDao.delete(id);
    }

    public PageVo<Case> queryByPage(String caseVoName, Integer categoryId , String orderby, String order, Integer pageIndex, Integer pageSzie){
        if(orderby==null||"".equals(orderby)){
            orderby="update_time";
        }
        if(order==null||"".equals(order)){
            order="desc";
        }
        PageVo pageVo = new PageVo(pageIndex);
        pageVo.setRows(pageSzie);
        pageVo.setList(caseVoCaseDao.queryByPage(caseVoName,categoryId,orderby,order,pageVo.getOffset(),pageVo.getRows()));
        pageVo.setCount(caseVoCaseDao.countCase(caseVoName,categoryId));
        return pageVo;
    }

    public List<Case> queryByIds(List<Integer> Ids){
        return caseVoCaseDao.queryByIds(Ids);
    }

}
